|
|
|
|
|
|
|
This function accepts two parameters (the object and requested rights level), and it returns TRUE or FALSE depending on whether the user has been granted the requested rights level. If no rights level is on file, this function returns zero (no access). |
|
|
|
|
|
|
|
|
Now save the DLL project files. Next, you add code to the Test project that uses the access rights to limit user access to the system. |
|
|
|
|
|
|
|
|
For this example, you check the user's login rights at the very start of the application. If they do not have the proper rights, they cannot see the first screen. |
|
|
|
|
|
|
|
|
The code in Listing 21.33 shows how the Main method should now look. This version of Main checks the user's access rights to the user maintenance form before displaying it to the user. |
|
|
|
|
|
|
|
|
Listing 21.33. Before the change in the Main procedure. |
|
|
|
|
|
|
|
|
Public Sub Main()
'
' main entry for form-less project
'
Set objUser = New usrObject
objUser.DBName = App.Path & "\..\..\data\security\security.mdb"
'
' now try to start up
If objUser.UserLogin = True Then
If objUser.CheckRights("UserMaint", urReadModAdd) Then
objUser.UsersForm
Else
MsgBox "You do not have rights to this application", vbExclamation,
"Login Failed"
End If
objUser.LogUser urLogOut
End If
'
End
'
End Sub |
|
|
|
|
|
|
|
|
That's it! Now save and run the test project. This time, log into the application using MCA as the user and the password. This user does not have the proper rights to the User Maintenance data entry form. When you attempt to log in, you get a message telling you that you do not have rights to run the application (see Figure 21.10). |
|
|
|
|
|
|
|
|
Figure 21.10.
Failing the rights validation test. |
|
|
|
|
|